﻿package IOException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class FileWriterExample {
	public static void main(String[] args) throws IOException {
		String source = "Người sống bằng hy vọng thế nào cũng chết vì nhịn đói!"
						+"dfdfg ô ê â đ "
						+"#%#%#$%# 34345 #$%#$% 34";
		char buffer[] = new char[source.length()];
		
		//bat dau lay tu vtri dau tien, toan bo chuoi, dua vao buffer
		source.getChars(0, source.length(), buffer, 0);
		
		FileWriter fw = new FileWriter("file1.txt");
		for(int i = 0; i < source.length(); i++) {
			fw.write(buffer[i]);
		}
		
		fw.close();
		
		FileWriter fw2  = new FileWriter("file2.txt");
		//ghi tat ca vao buffer
		fw2.write(buffer);
		fw2.close();
		
		FileWriter fw3 = new FileWriter("file3.txt");
		//ghi chuoi vao buffer, bat dau tu vtri thu 2 den vtri thu 9
		fw3.write(buffer, 2, 9);
		fw3.close();
	}

}
